package com.example.studyapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

/**
 * @data on 2020/9/25 9:05 AM
 * @auther armStrong
 * @describe Recycler使用
 */
class RecyclerAdapter(private val textList: ArrayList<String>) :
    RecyclerView.Adapter<RecyclerAdapter.MyViewHolder>() {

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.choice_item, parent, false)
        return MyViewHolder(view)
    }

    override fun getItemCount(): Int = textList.size ?: 0

    override fun onBindViewHolder(holder: RecyclerAdapter.MyViewHolder, position: Int) {
        val textpos = textList[position]
        holder.title.text = textpos
        holder.itemView.setOnClickListener {//点中列表
            Toast.makeText(holder.itemView.context, "${holder.title.text}", Toast.LENGTH_SHORT)
                .show()
        }
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val title: TextView = itemView.findViewById(R.id.item_view_text1)
    }
}

class choice : AppCompatActivity() {
    private val textList = arrayListOf("我的关注","通知开关", "我的徽章", "意见反馈", "我要投稿",
        "我的关注","通知开关", "我的徽章", "意见反馈", "我要投稿",
        "我的关注","通知开关","我的徽章","意见反馈","我要投稿")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_choice)
        val layoutManager=LinearLayoutManager(this)
        val mre:RecyclerView=this.findViewById(R.id.choice_recyclerview)
        mre.layoutManager=layoutManager
        val adapter=RecyclerAdapter(textList)
        mre.adapter=adapter

    }
}